package com.rocketmq.plugins;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import com.jfinal.plugin.IPlugin;

public class RocketMqProducerPlugin implements IPlugin {
 
 
    private static DefaultMQProducer producer = new DefaultMQProducer(MqConfig.TOPIC);

    @Override
    public boolean start() {
        try {
            // 指定NameServer的地址
            producer.setNamesrvAddr(MqConfig.ENDPOINT);
            // 第一次发送可能会超时，我设置的比较大
            producer.setSendMsgTimeout(60000);
            // 启动生产者
            producer.start();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean stop() {
        producer.shutdown();
        return true;
    }


    public static DefaultMQProducer getProducer(){
        return producer;
    }

}
